﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp1.bean;
using WpfApp1.mysqlunit;

namespace WpfApp1
{
    /// <summary>
    /// ScanRecordLog.xaml 的交互逻辑
    /// </summary>
    /// 
    public partial class ScanRecordLog : Window
    {


        public static Dictionary<String, scanRecordBean> scanRecordBeans = new Dictionary<String, scanRecordBean>();
        MysqlData mysqldata;
        public ScanRecordLog()
        {
            InitializeComponent();
            mysqldata = MysqlData.createMysqlData();
            starttime.SelectedDate = DateTime.Now;

 

            starttime.SelectedDate = DateTime.Now.AddDays(-7);
            endtime.SelectedDate = DateTime.Now.AddDays(1);
        }
        public void  initdata()
        {
            
            listpackage.Items.Clear();
            foreach (KeyValuePair<String, scanRecordBean> p in scanRecordBeans)
            {
                scanRecordBean bean = p.Value;
                listpackage.Items.Add(bean);
            }
            listpackage.Items.Refresh();
            
        }

        private void Button_SouSUo(object sender, RoutedEventArgs e)
        {
            DateTime? startDate = starttime.SelectedDate;
            string sttime = "";
            string edtime = "";
            if (startDate.HasValue)
            {
                string formatted = startDate.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                
                DateTime yesTime = Convert.ToDateTime(formatted);
                DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
                int timeStamp = Convert.ToInt32((yesTime - dateStart).TotalSeconds);
                sttime = timeStamp + "";
            }
           
            DateTime? endDate = endtime.SelectedDate;
            if (endDate.HasValue)
            {
                string formatted = endDate.Value.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                DateTime yesTime = Convert.ToDateTime(formatted);
                DateTime dateStart = new DateTime(1970, 1, 1, 8, 0, 0);
                int timeStamp = Convert.ToInt32((yesTime - dateStart).TotalSeconds);
                edtime = timeStamp + "";
            }
            scanRecordBeans.Clear();
            mysqldata.read_scan_record(TB_scan_string.Text.Trim(),scanRecordBeans,sttime,edtime);
            initdata();
        }


        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

    }
}
